<?php

//////////////////////////////////////////// 
//			Обработчик формы			 ///
////////////////////////////////////////////

$_POST['first_name'] = trim($_POST['first_name']);
$_POST['second_name'] = trim($_POST['second_name']);
$_POST['last_name'] = trim($_POST['last_name']);
$_POST['country'] = trim($_POST['country']);
$_POST['mailaddr'] = trim($_POST['mailaddr']);
$_POST['id_referer_1'] = trim($_POST['id_referer_1']);
$_POST['id_referer_2'] = trim($_POST['id_referer_2']);
$_POST['id_referer_3'] = trim($_POST['id_referer_3']);
$_POST['id_referer_4'] = trim($_POST['id_referer_4']);
$_POST['numusr'] = trim($_POST['numusr']);
$_POST['timefrom'] = trim($_POST['timefrom']);
$_POST['timeto'] = trim($_POST['timeto']);
 
$result_check = '';
 
/* Result Check

0101 - nameError
0102 - SecondNameError
0103 - LastNameError
0204 - CountryError
0303 - mailError
0304 - idRefererError
0404 - UserNumber

0410 - TimeCallto
0411 - TomeCallOver

0502 - userAge
0501 - userPolicy
*/

if(empty($_POST['first_name'])) $result_check = "Имя пользователя";
if(empty($_POST['second_name'])) $result_check = "Фамилия пользователя";
if(empty($_POST['last_name'])) $result_check = "Отчество";
if(empty($_POST['country'])) $result_check = "Страна, город";
if(empty($_POST['id_referer_1'])) $result_check = "ID пригласившего";
if(empty($_POST['id_referer_2'])) $result_check = "ID пригласившего";
if(empty($_POST['id_referer_3'])) $result_check = "ID пригласившего";
if(empty($_POST['id_referer_4'])) $result_check = "ID пригласившего";
if(empty($_POST['mailaddr']))$result_check = "Почта";
if(empty($_POST['numusr'])) $result_check = "Номер телефона";
if(empty($_POST['timefrom'])) $result_check = "Время с";
if(empty($_POST['timeto'])) $result_check = "Время до";
if($_POST['ageres'] != true) $result_check = "Возраст";
if($_POST['userPolicy'] != true) $result_check = "Соглашение";

if (!empty($_POST['mailaddr']))
 {
    if(!preg_match("/^[0-9a-z_]+@[0-9a-z_^.]+\\.[a-z]{2,3}/", $_POST['mailaddr'])){
        $result_check = "Почта";
       }       
 }
 

if (!empty($result_check)){
	$result_check = $errorlist;
	include('sys/errorch.php');

}
else{
 
if (!get_magic_quotes_gpc())
{
$_POST['first_name'] = mysql_escape_string($_POST['first_name']);    
$_POST['second_name'] = mysql_escape_string($_POST['second_name']);
$_POST['last_name'] = mysql_escape_string($_POST['last_name']);
$_POST['country'] = mysql_escape_string($_POST['country']);
$_POST['mailaddr'] = mysql_escape_string($_POST['mailaddr']);
$_POST['timefrom'] = mysql_escape_string($_POST['timefrom']);
$_POST['timeto'] = mysql_escape_string($_POST['timeto']);
}
 

$timefrom = $_POST['timefrom'];
$timeto = $_POST['timeto'];
$calltime = $timefrom += $timeto;

require_once('_includes/dbconfig.php');
include('sys/id_generator.php');

$sys_uid = $id_new_user;
 
$photo = "no photo";

$iref1 = $_POST['id_referer_1'];
$iref2 = $_POST['id_referer_2'];
$iref3 = $_POST['id_referer_3'];
$iref4 = $_POST['id_referer_4'];


$ref_id = $iref1 + $iref2 + $iref3 + $iref4;

/////////////////////////////////////
/// Блок регистрации пользователя///
////////////////////////////////////
 

mysql_query('SET NAMES UTF8');

$query =  "INSERT INTO user_info (name, se_name, lt_name, country, id_ref, mail, photo, tel_num, call_time, uid)
            VALUES('$_POST[first_name]',
                    '$_POST[second_name]',
                    '$_POST[last_name]',
                    '$_POST[country]',
					'$_POST[id_referer]',
                    '$_POST[mailaddr]',
					'".$photo."',
                    '$_POST[numusr]',
					'".$calltime."',
					'".$sys_uid."')";
 

if(mysql_query($query))
{
include('registration_info.php');

} else{
	//include('sys/error.php');
	echo("Ошибка при добавлении данных - ".mysql_error());
}
}
?>
 
